/*
 * @Descripttion:获取自动接口信息
 * @version:
 * @Author: 麦冬果果
 * @Date: 2021-07-15 09:32:14
 * @LastEditors: 麦冬果果
 * @LastEditTime: 2021-09-11 08:55:41
 */
package hook

import (
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
)

func init() {
	HookList.Append(getApi)
}

var getApi = HookEntity{
	FuncName: "getApi",
	Style:    "BEFORE_SERVE_DEFAULT",
	Param:    nil,
	Run:      GetApi,
}

func GetApi(r *ghttp.Request) {
	params := g.Map{
		"gname": r.GetString("-gname"),
		"ename": r.GetString("-ename"),
	}
	appApi, err := GetOneAppApiByNames(params)
	if err != nil {
		g.Log().Error(err)
		r.SetCtxVar("err", true)
		r.SetCtxVar("errMsg", "获取接口失败")
		return
	}
	if appApi == nil {
		r.SetCtxVar("err", true)
		r.SetCtxVar("errMsg", "无接口信息")
		return
	}
	if appApi.Status == "1" {
		r.SetCtxVar("err", true)
		r.SetCtxVar("errMsg", "接口关闭")
		return
	}
	r.SetCtxVar("appApi", appApi)
}
